import sys
sys.path.append('../')

from ArxmlBasicTools.SwcAutoConfig import SwcComponentConfig
from ArxmlBasicTools.SwcAutoConfig import SwcArxmlFile

def addEventRPort(SwcComponent: SwcComponentConfig,eventName):
    SwcComponent.addSwcCSRPort('PC_Monitor_' + eventName,'/AUTOSAR_Dem/PortInterfaces/DiagnosticMonitor')
    SwcComponent.addSwcCSRPort('PC_Info_' + eventName,'/AUTOSAR_Dem/PortInterfaces/DiagnosticInfo')

def addEventStatusServerCall(SwcComponent: SwcComponentConfig,runnableName,eventName):
    SwcComponent.addServerCall(runnableName,'PC_Monitor_'+ eventName,'/AUTOSAR_Dem/PortInterfaces/DiagnosticMonitor/SetEventStatus')
    SwcComponent.addServerCall(runnableName,'PC_Info_'+ eventName,'/AUTOSAR_Dem/PortInterfaces/DiagnosticInfo/GetEventStatus')

def addOpCycleRPort(SwcComponent: SwcComponentConfig):
    SwcComponent.addSwcCSRPort('PC_OpCycle','/AUTOSAR_Dem/PortInterfaces/OperationCycle')

def addOpCycleServerCall(SwcComponent: SwcComponentConfig,runnableName):
    SwcComponent.addServerCall(runnableName,'PC_OpCycle','/AUTOSAR_Dem/PortInterfaces/OperationCycle/SetOperationCycleState')
    SwcComponent.addServerCall(runnableName,'PC_OpCycle','/AUTOSAR_Dem/PortInterfaces/OperationCycle/GetOperationCycleState')

def addEnConditionRPort(SwcComponent: SwcComponentConfig,EnConditionName):
    SwcComponent.addSwcCSRPort('PC_' + EnConditionName,'/AUTOSAR_Dem/PortInterfaces/EnableCondition')       
    
def addEnConditionServerCall(SwcComponent: SwcComponentConfig,runnableName,EnConditionName):
    SwcComponent.addServerCall(runnableName,'PC_' + EnConditionName,'/AUTOSAR_Dem/PortInterfaces/EnableCondition/SetEnableCondition')
                        
class DemSwcConfig(SwcComponentConfig):
    def __init__(self,path: str, name: str ='SWC_NameNodefine') -> None:
        super(DemSwcConfig, self).__init__()
        self.createComponent_el(path,name)

def createDemSwcArxmlFile(PackagePath: str):
    DemSwcFile = SwcArxmlFile()
    DemSwcFile.createSwcArxmlFile(PackagePath)
    return DemSwcFile

def addDemSwcComponentInSwcFile(DemSwcFile: SwcArxmlFile,Component: SwcComponentConfig):
    DemSwcFile.addComponent(Component)

def paraseDemSwcArxmlFile(arxmlFileName,PackagePath: str):
    DemSwcFile = SwcArxmlFile()
    DemSwcFile.paraseSwcArxmlFile(arxmlFileName,PackagePath)
    return DemSwcFile

#autoMapping
from ArxmlBasicTools.SystemAutoConfig import SystemArxmlFile
from ArxmlBasicTools.SystemAutoConfig import CompositionConfig

def createDemSystemArxmlFile(PackagePath: str):
    systemFile = SystemArxmlFile()
    systemFile.createSystemArxmlFile(PackagePath)
    return systemFile

def createDemCompisition(systemFile:SystemArxmlFile,path,name):
    composition = CompositionConfig(path,name)
    #add default dem bsw component
    dem = SwcComponentConfig('/AUTOSAR_Dem/SwComponentTypes','Dem')
    composition.addComponent(dem,False)
    systemFile.addComposistion(composition)
    return composition

def addDemSwcComponentInCompostion(composition:CompositionConfig,DemSwc:SwcComponentConfig):
    composition.addComponent(DemSwc,False)

def addOpCycleConnector(composition:CompositionConfig,demSwcName):
    composition.addConnectors('Dem','OpCycle_DemOperationCycle',demSwcName,'PC_OpCycle')

def addEnableCondConnector(composition:CompositionConfig,demSwcName,enableCondName):
    composition.addConnectors('Dem','EnableCond_DemEnableCondition_' + enableCondName,demSwcName,'PC_' + enableCondName)

def addEventConnector(composition:CompositionConfig,demSwcName,eventName):
    composition.addConnectors('Dem','Event_' + eventName,demSwcName,'PC_Monitor_' + eventName)
    composition.addConnectors('Dem','EvtInfo_' + eventName,demSwcName,'PC_Info_' + eventName)
